package com.hqj.client.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqj.client.entity.BlogsCollect;
import com.hqj.client.mapper.BlogsCollectMapper;
import com.hqj.client.service.BlogsCollectService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author 黄啟军
 * @version 1.0
 * @date 2020/5/16/016
 */
@Service
public class BlogsCollectServiceImpl implements BlogsCollectService {

    @Resource
    private BlogsCollectMapper blogsCollectMapper;
    /**
     * BlogsCollect分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public List<BlogsCollect> findPage(int page, int size){
        //QueryWrapper<BlogsCollect> wrapper = new QueryWrapper<>();
        IPage<BlogsCollect> findpage = blogsCollectMapper.selectPage(new Page<>(page, size),null);
        return findpage.getRecords();
    }
    /**
     * 删除
     * @param id
     */
    @Override
    public int delete(Long id){
        BlogsCollect blogsCollect = blogsCollectMapper.selectById(id);
       // blogsCollect.setIsDelete(1);
        return blogsCollectMapper.updateById(blogsCollect);
    }
    /**
     * 修改BlogsCollect
     * @param blogsCollect
     */
    @Override
    public int update(BlogsCollect blogsCollect){

        return blogsCollectMapper.updateById(blogsCollect);
    }
    /**
     * 增加BlogsCollect
     * @param blogsCollect
     */
    @Override
    public int add(BlogsCollect blogsCollect){
       return blogsCollectMapper.insert(blogsCollect);
    }
    /**
     * 根据ID查询BlogsCollect
     * @param id
     * @return
     */
    @Override
    public BlogsCollect findById(Long id){
        return  blogsCollectMapper.selectById(id);
    }
    /**
     * 查询BlogsCollect全部数据
     * @return
     */
    @Override
    public List<BlogsCollect> findAll() {
        return blogsCollectMapper.selectList(null);
    }
    /**
     * 判断是否收藏
     * @date 2020/10/28 16:55
     * @param typeId
     * @param userName
     * @return com.hqj.client.entity.BlogsCollect
     */
    @Override
    public BlogsCollect judgeCollect(Integer typeId, String userName) {
        QueryWrapper<BlogsCollect>wrapper=new QueryWrapper<>();
        wrapper.eq("is_delete",0).eq("type_id",typeId).eq("user_name",userName);
        return blogsCollectMapper.selectOne(wrapper);
    }
}
